package com.xingu.xg.controller;

import com.xingu.xg.po.TreeStructure;
import com.xingu.xg.service.TreeStructureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 于卜
 * @ProjectName: xg-interview-java-master
 * @Package: com.xingu.xg.controller
 * @ClassName: TreeStructureController
 * @Description: TODO
 * @Date: 2024/5/15 13:26
 * @Version: 1.0
 */
@RestController
@Slf4j
public class TreeStructureController {
    @Resource
    private TreeStructureService treeStructureService;

    //若id为空查询所有父节点
    //可以根据首次查询出来的父节点的id匹配子节点的parent_id
    @RequestMapping("/get")
    public List<TreeStructure>  get(@RequestParam(required = false) Integer id){
        List<TreeStructure> list  = treeStructureService.get(id);
        return list;
    }

    //添加一个节点
    @RequestMapping("/add")
    public boolean add(@RequestParam String name,@RequestParam(required = false) Integer parentId){
        TreeStructure treeStructure = new TreeStructure();
        treeStructure.setName(name);
        treeStructure.setParentId(parentId);
        boolean b = treeStructureService.add(treeStructure);
        return b;
    }



   //根据id删除一个节点
    @RequestMapping("/delete")
    public boolean delete(@RequestParam Integer id){
        boolean b = treeStructureService.delete(id);
        return b;
    }




}
